from django.shortcuts import render_to_response
from django.template import RequestContext

from wiki.models import Strona

def render(function):
    def _render(request, *args, **kwargs):
        value = function(request, *args, **kwargs)
        if value.__class__.__name__ == 'HttpResponseRedirect':
            return value
        else:
            template_name, context = value[0], value[1]
        return render_to_response(template_name, locals(), context_instance=RequestContext(request, context))
    return _render

def strona_lub_None(tytul_url):
    try:
        strona = Strona.objects.get(tytul_url=tytul_url)
    except:
        strona = None
    return strona
